package com.acxy.b2b2c.service;

import com.acxy.ants.common.enums.DataSourceType;
import com.acxy.ants.core.annotation.Service;
import com.acxy.ants.core.annotation.Source;
import com.acxy.ants.core.kit.LogKit;
import com.acxy.ants.core.plugin.db.Db;
import com.acxy.ants.resful.bean.Page;
import com.acxy.b2b2c.entity.Member;
import com.alibaba.fastjson.JSON;

/**
 * 会员业务类
 * @author MrShun
 * @version 1.0
 * @Date 2017-10-10
 */
@Service
public class MemberService {

    @Source(DataSourceType.DRUID)
    private Db db;

    public Page queryPage(Integer pageIndex, Integer pageSize, String sortField, String sortOrder, String filters, String tjKey, String keyValue) {
        Member member = null;
        try {
            if (filters != null)
                member = JSON.parseObject(filters, Member.class);
            else
                member = new Member().orderBy(sortField, sortOrder);
            if (tjKey != null && keyValue != null)
                member.search(tjKey, keyValue);
        } catch (Exception e) {
            LogKit.error("conditional conversion error:{}", filters);
        }
        Page page = member.page(db, pageIndex, pageSize);
        return page;
    }
}
